*** This file generates/replicates the analysis for:
	* Table 1
	* Table 2
	* Table 3
	* Table 4 (Panel A), 
	* Table A.1. (Columns (1) and (2)), 
	* Table A.2. 
	* Table A.3. Columns (1) through (4),  
	* Table D.1. 
	* Table D.2. 
	* Figure 1.A 
	* Table 1.B  
    * Appendix Figure B.1.

	

*****	
	

clear all
set matsize 1000
set maxvar 20000
set more off
pause on


*** Start dataset 

clear
use replication-1.dta


***************
gen mineval=minutes/evaluations
label var mineval "minute per cookie tasted and evaluated by subject"


tabulate week, gen(w)
tabulate treat, gen(t)
tabulate leg, gen(l)

gen t1Xw1=t1*w1
gen t1Xw2=t1*w2

gen t2Xw1=t2*w1
gen t2Xw2=t2*w2

gen t3Xw1=t3*w1
gen t3Xw2=t3*w2


* campusXleg fixed effects
egen legcampus=concat(leg campus) 
tabulate(legcampus), gen(legcampus)


* campusXlegXsession fixed effects
egen legcampusweek=concat(leg campus week) 
tabulate(legcampusweek), gen(legcampusweek)


*
gen quit=1 if week==2 & evaluations==. 
replace quit=0 if quit==.
label var quit "=1 if subject quit into session 2;=0 otherwise"

gen evaluations1=evaluations
replace evaluations1=0 if evaluations1==.
label var evaluations1 "cookies tasted and evaluated assuming quitting subjects supply 0 evaluations"

gen minutes1=minutes
replace minutes1=0 if minutes1==.
label var minutes1 "minutes tasting and evaluating assuming quitting subjects supply 0 minutes"


****

save replication-2.dta, replace


***************************************************************************************************************
***************************************************************************************************************

*TABLE 1: 

** summary statistics
su evaluations mineval minutes  partprop


*******************************************************************************************
*TABLE 2: 

by week treat, sort: su evaluations mineval minutes  

** with those who quit supplying zero output and zero time

by treat, sort: su evaluations1 minutes1  if week==2



*******************************************************************************************
*TABLE 3: OLS


** UNADJUSTED WEEK 1

*Baseline is t1Xw1 (Control in week 1)
reg evaluations  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2, cluster(id)


reg mineval  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2  , cluster(id)



** UNADJUSTED WEEK 2
*Baseline is t1Xw2 (Control in week 2)

reg evaluations  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 , cluster(id)

reg mineval  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2  , cluster(id)



***********************************************************************
* Table 4, Panel A


** WEEK 1: with campus, leg and week fixed effects 
*Baseline is t1Xw1 (Control in week 1)

reg evaluations  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14, cluster(id)

reg mineval  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14, cluster(id)


**** WEEK 2 - with campus, leg and week fixed effects 
*Baseline is t1Xw2 (Control in week 2)

reg evaluations  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14, cluster(id)

reg mineval  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14, cluster(id)



***********************************************************************
* TABLE A.1. (Columns (1) and (2))

reg quit t2 t3 if week==2 , robust
reg quit t2 t3 legcampus1-legcampus7 if week==2 , robust




***********************************************************************
* TABLE A.2. 

** OUTPUT- UNADJUSTED OLS WEEK 1

reg evaluations1  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2, cluster(id)

** OUTPUT-UNADJUSTED OLS WEEK 2

reg evaluations1  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 , cluster(id)


*** MINUTES UNADJUSTED OLS WEEK 1
reg minutes1  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2 , cluster(id)

*** MINUTES UNADJUSTED OLS WEEK 2
reg minutes1  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2, cluster(id)



** OUTPUT - FIXED EFFECTS- WEEK 1
reg evaluations1  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14, cluster(id)

** OUTPUT-FIXED EFFECTS-WEEK 2
reg evaluations1  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14, cluster(id)


**** MINUTES FIXED EFFECTS-WEEK 1
reg minutes1  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14, cluster(id)


** MINUTES FIXED EFFECTS-WEEK 2

reg minutes1  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14, cluster(id)


***********************************************************************

* TABLE A.3. -- Columns (1) through (4) 

** Unadjusted - week 1
reg minutes  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2  , cluster(id)

** Unadjusted - week 2
reg minutes  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2  , cluster(id)



** FE - week 1
reg minutes  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14, cluster(id)

** FE - week 2

reg minutes  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14, cluster(id)


**************************************************************************

* TABLE B.1., Panel A, Columns (1)  and (3)

* Session One 
reg evaluations  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2 if quitters_t3!=1, cluster(id)

reg evaluations t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14 if quitters_t3!=1,  cluster(id)


* TABLE B.1., Panel A, Columns (2)  and (4)

*Session 2

reg evaluations  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 if  quitters_t3!=1, cluster(id)

reg evaluations t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14  if  quitters_t3!=1,  cluster(id)


****
* TABLE B.1., Panel B, Columns (1)  and (3)

* Session One 
reg mineval  t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2 if quitters_t3!=1, cluster(id)


reg mineval t1Xw2 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14 if quitters_t3!=1,  cluster(id)


* TABLE B.1., Panel B, Columns (2)  and (4)


*Session 2
reg mineval  t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 if quitters_t3!=1, cluster(id)

reg mineval t1Xw1 t2Xw1 t2Xw2 t3Xw1 t3Xw2 legcampusweek1-legcampusweek14 if quitters_t3!=1,  cluster(id)


**************************************************************************
* Table B.2. 

by quitters_t3, sort: su evaluations mineval  if treat==3 & week==1

ranksum evaluations if treat==3 & week==1, by(quitters_t3) 
ranksum mineval if treat==3 & week==1, by(quitters_t3) 


**************************************************************************
* TABLE D.1. 

by campus treat week, sort: su evaluations mineval


***********************************************************************
* TABLE D.2. 

by leg treat week, sort: su evaluations mineval


********************************* FIGURES ***************
* FIGURE 1.A - CDF evaluations


** Week 1- evaluations

distplot evaluations if week==1 & (treat==1| treat==2 | treat==3) , recast(connected) ///
title ("Session One (Reward)") legend(order(1 "Control" 2 "Unanticipated" 3 "Anticipated")) ///
ytitle("Cumulative Probability") xtitle("Number of Evaluations") over(treat) scheme(s2manual)

graph save evaluations-s1, replace


** Week 2 -evaluations


distplot evaluations if week==2 & (treat==1| treat==2 | treat==3) , recast(connected) ///
title ("Session Two (Non-Reward)") legend(order(1 "Control" 2 "Unanticipated" 3 "Anticipated")) ///
ytitle("") xtitle("Number of Evaluations") over(treat) scheme(s2manual)

graph save evaluations-s2, replace


* combined graph: Figure 1.A
graph combine evaluations-s1.gph evaluations-s2.gph, xcommon ycommon imargin(0 0 5 0) subtitle("A. Output CDFs Per Condition and Session") 
graph save evaluationsg, replace


***************************************************************************************************************
* FIGURE 1.B - CDF minutes per evaluation


distplot mineval if week==1 & (treat==1| treat==2 | treat==3) , recast(connected) ///
title ("Session One (Reward)") legend(order(1 "Control" 2 "Unanticipated" 3 "Anticipated")) ///
ytitle("Cumulative Probability") xtitle("Minutes per Evaluation") over(treat) scheme(s2manual)

graph save mineval-s1, replace


distplot mineval if week==2 & (treat==1| treat==2 | treat==3) , recast(connected) ///
title("Session Two (Non-Reward)") legend(order(1 "Control" 2 "Unanticipated" 3 "Anticipated")) ///
ytitle("") xtitle("Minutes per Evaluation") over(treat) scheme(s2manual)

graph save mineval-s2, replace

* combined graph: Figure 1.B. 
graph combine mineval-s1.gph mineval-s2.gph,  xcommon ycommon imargin(0 0 5 0) subtitle("B. Productivity CDFs Per Condition and Session") 
graph save minevalg, replace


*** Combined graph: Figure 1. A and 1.B
graph combine evaluationsg.gph minevalg.gph,  row(2) col(1) iscale(0.7) ysize(6) xsize(4)
graph save evag-prodg-combog, replace


***************************************************************************************************************
* FIGURE B.1. 

distplot mineval if week==1 & (treat==1| treat==2 | treat==3) & quitters_t3!=1, recast(connected) ///
title( "Session One (Reward)" "Subsample of Non-Quitters in the Anticipated Condition") ///
legend(order(1 "Control" 2 "Unanticipated" 3 "Anticipated (subsample of non-quitters)")) ytitle("Cumulative Probability") xtitle("Minutes per Evaluation") over(treat) scheme(s2manual)

graph save mineval-na-t3-w1, replace

** Combine graph 
graph combine mineval-s1.gph mineval-s2.gph mineval-na-t3-w1.gph , hole(4) xcommon ycommon imargin(0 0 5 0)  iscale(*0.7) 
graph save minevalgcombo, replace



